package com.java.wmovie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.java.wmovie.entity.Movie;
import com.java.wmovie.entity.PageUtils;
import com.java.wmovie.mapper.MovieMapper;
import com.java.wmovie.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class HomeController {
    @Autowired
    MovieService movieService;
    @Autowired
    MovieMapper movieMapper;

    @RequestMapping("/")
    public String home(HttpSession session, Model model){
        String name= (String) session.getAttribute("loginUser");
        model.addAttribute("name",name);

        PageUtils pageUtils = new PageUtils(new Page(1, 5), "/home");
        Page<Movie> page = movieMapper.selectPage(pageUtils.getPage(),null);
        model.addAttribute("page",page);
        PageUtils pageUtils1 = new PageUtils(new Page(1, 6), "/home");
        Page<Movie> page1 = movieMapper.selectPage(pageUtils1.getPage(),null);
        model.addAttribute("page1",page1);
        return "/home";
    }
}
